#!/user/bin/env python
# coding:utf-8
"""
Author myYouTh
Date:2020/2/21 002115:43
Desc:数据描述符，用于参数类型检查
"""


class DataDescriptor(object):
    """数据描述符"""
    def __get__(self, instance, owner):
        """
        返回数据描述符的值
        :param instance:
        :param owner:
        :return:
        """
        return self.value

    def __set__(self, instance, value):
        pass

    def __delete__(self, instance):
        pass


class StrDataDescriptor(DataDescriptor):
    """字符串参数类型检查"""
    def __set__(self, instance, value):
        if not isinstance(value, str):
            raise NameError(f"{instance.__class__.__name__}类初始化失败，实参{value}的类型必须是字符串String")
        self.value = value


class DictDataDescriptor(DataDescriptor):
    """字典参数类型检查"""
    def __set__(self, instance, value):
        if not isinstance(value, dict):
            raise NameError(f"{instance.__class__.__name__}类初始化失败， 实参{value}的类型必须是字典Dict")
        self.value = value